package com.kkwrite.regimen.common.constant;

/**
 * Created by lisha on 2018/7/19 21:39.
 *
 * @author lisha
 */
public enum ShareTypeEnum {

    /**
     * 邀请好友
     */
    INVITE_FRIENDS("邀请好友", (short) 1),
    /**
     * 分享项目
     */
    SHARING_PROJECT("分享项目", (short) 2)

    ;
    private String typeName;
    private Short typeValue;

    ShareTypeEnum(String typeName, Short typeValue) {
        this.typeName = typeName;
        this.typeValue = typeValue;
    }

    public String getTypeName() {
        return typeName;
    }

    public Short getTypeValue() {
        return typeValue;
    }

    /**
     * 依据分享类型值查找分享类型
     * @param value 值
     * @return 若找到返回类型名，否则，返回null
     */
    public static String findTypeName(short value) {
        if (value < 0) {
            return null;
        }
        for (ShareTypeEnum typeEnum : ShareTypeEnum.values()) {
            if (typeEnum.getTypeValue() == value) {
                return typeEnum.getTypeName();
            }
        }
        return null;
    }

    /**
     * 依据分享类型名查找分享类型值
     * @param name 分享类型名
     * @return 若找到返回其值，否则，返回-1
     */
    public static Short findTypeValue(String name) {
        if (name == null || name.isEmpty()) {
            return -1;
        }
        for (ShareTypeEnum typeEnum : ShareTypeEnum.values()) {
            if (typeEnum.getTypeName().equals(name)) {
                return typeEnum.getTypeValue();
            }
        }
        return -1;
    }

}
